<?php	
	include ("asset/config/koneksi.php");
	$nama = $_POST['bank'];
	if ($nama!='') {
		$lokasi_file=$_FILES['gambar']['tmp_name'];
		$nama_file=$_FILES['gambar']['name'];
		$tipe_file=$_FILES['gambar']['type'];
		//buat nama file yang unik
		$acak=rand(0000,9999);
		$nama_file_unik=$acak.$nama_file;
		$msg = "Data $lokasi_file";
		if(!empty($lokasi_file)) {
			// Apabila tipe gambar bukan jpeg akan tampil peringatan
    		if ($tipe_file != "image/jpeg" and
				$tipe_file != "image/png" and 
				$tipe_file != "image/gif"){
				$msg = "Data harus berupa jpeg / png / gif";
      		} else {
				move_uploaded_file($lokasi_file,"../images/$nama_file_unik");
				$q = "INSERT INTO bank(nama_bank, no_rek, pemilik, gambar) VALUES ('$nama','$_POST[rekening]','$_POST[pemilik]','$nama_file_unik')";
				$r = mysql_query($q) or die (mysql_error());
				if($r) {
					$msg = "Data sudah ditambahkan";
				}
				else {
					$msg = "Data tidak bisa dimasukkan";
				}
			}
		}
	}
	echo "<meta http-equiv='refresh' content='0; url=utama.php?module=mod_bank'>";
?>